﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text;
using System.Collections;
using Eis51.CampanyCMS.Model;
using Eis51.CampanyCMS.Model.NewsManager.QueryO;
using Eis51.CampanyCMS.Business.NewsManager;
using Eis51.CampanyCMS.Model.NewsManager;

namespace Eis51.Web.dataPage
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class CustomerHeadDT : IHttpHandler
    {
        private int Seqno;

        public void ProcessRequest(HttpContext context)
        {
            if (!Check(context))
            {
                return;
            }
            context.Response.ContentType = "text/plain";
            StringBuilder sb = new StringBuilder();

            LoadNews(context, ref sb);

            context.Response.Write("[ " + sb.ToString() + "]");
        }

        private bool Check(HttpContext context)
        {
            if (string.IsNullOrEmpty(context.Request.QueryString["seqno"]))
            {
                return false;
            }
            return true;
        }

        public class ShowModel
        {

            public int Seqno { get; set; }

            public string Title { get; set; }

        }


        private void LoadNews(HttpContext context,ref StringBuilder hoemData)
        {
            try
            {
                Seqno = int.Parse(context.Request.QueryString["seqno"]);
            }
            catch (Exception ex)
            {
                return;
            }
            CustomerQuery query = new CustomerQuery();
            query.Licd = (Eis51.CampanyCMS.FrameWork.Licd)AppContext.LCID;
            query.Type = Seqno;
            query.IsFist = true;
            IList list = CustomerBLL.GetInstance().Search(query);

            ShowModel showModel = null;
            Customer model = null;
            string tmpStr = string.Empty;

            if (null != list && list.Count > 0)
            {
                foreach (var et in list)
                {
                    model = (Customer)et;
                    if (string.Empty.Equals(model.Title))
                    {
                        continue;
                    }
                    showModel = new ShowModel { Seqno = model.Seqno, Title = model.Title };
                    tmpStr = Eis51.Web.common.common.JavaScriptSerializerString(showModel);
                    hoemData.Append(",");
                    hoemData.Append(tmpStr);
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
